package com.group4.xiao_ge_lai_yi_zhu.controller.login_controller;

import com.group4.xiao_ge_lai_yi_zhu.entry.Entry;
import com.group4.xiao_ge_lai_yi_zhu.service.LoginService;

import java.util.Scanner;

/**
 * 登录界面
 * 对用户执行登录操作
 */
public class LoginPage {
    public static String getUsername;
    private Scanner sc = new Scanner(System.in);
    private LoginService loginService = new LoginService();
    private HomePage homePage = new HomePage();
    String username;
    String password;

    /*
        登录的方法:对用户进行登录操作
     */
    public void login() {
        Entry entry = new Entry();
        while (true) {
            System.out.println("请输入用户名:");
            username = sc.nextLine();
            boolean exist = loginService.usernameExist(username);
            if (!exist) {
                System.out.println("请输入密码:");
                password = sc.nextLine();
                boolean exist1 = loginService.passwordExist(username, password);
                if (exist1) {
                    System.out.println("登录成功");
                    getUsername = username;
                    homePage.page();
                    break;
                } else {
                    System.out.println("密码错误,登录失败");
                    entry.entry();
                }
            } else {
                System.out.println("没有此用户,请重新输入");
                entry.entry();
            }
        }
        /*boolean flag = loginService.register(username, password);
        if (!flag) {
            //登录之后的页面
            homePage.page();
            flag = true;
        } else {
            System.out.println("此账号正在登陆中");
        }*/
    }
}
